package entity_model.json.deserializers;

import com.google.gson.*;
import entity_model.Attribute;
import entity_model.data_types.DataTypes;
import utils.titles.Title;

import java.lang.reflect.Type;

/**
* Created by nuno-rafael-figueiredo on 13-05-2014.
*/
public class AttributeDeserializer implements JsonDeserializer<Attribute> {
    @Override
    public Attribute deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
        final JsonObject jsonObject = json.getAsJsonObject();

        return new Attribute(
                DataTypes.valueOf(jsonObject.get("type").getAsString()),
                Title.fromCapitalized(jsonObject.get("name").getAsString())
        );
    }
}
